<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">客户新建</p>
    </div>
    <div class="view-container">
      <el-row class="status-title">
        <el-col class="mr20 width100">
          <el-button
            class="btn-success width100"
            type="primary"
            @click="submitForm(1)"
          >保存</el-button>
        </el-col>
        <el-col class="mr20 width100">
          <el-button
            class="btn-success width100"
            type="primary"
            @click="submitForm(2)"
          >提交</el-button>
        </el-col>
        <el-col :span="10" class="status-container">
          <div class="status-item">
            <span class="active">草稿</span>
            <span>待审核</span>
            <span>已审核</span>
            <span>拒绝</span>
          </div>
        </el-col>
      </el-row>
      <el-form ref="form" :model="form" label-width="140px" class="mt30">
        <ul class="tabs">
          <li @click="current = 0" :class="{ active: current === 0 }">基础资料</li>
          <li @click="current = 1" :class="{ active: current === 1 }">证件管理</li>
          <li @click="current = 2" :class="{ active: current === 2 }">开票信息</li>
        </ul>
        <div v-show="current === 0">
          <el-row>
            <el-col :span="8">
              <el-form-item label="客户代码:" prop="code">
                <el-input v-model="form.code" placeholder="系统自动生成" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="客户全称:" prop="name" class="icon-star">
                <el-input v-model="form.name" placeholder="请输入客户全称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="英文名称:" prop="englishName">
                <el-input v-model="form.englishName" placeholder="请输入英文名称" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="客户简称:" prop="abbreviation">
                <el-input v-model="form.abbreviation" placeholder="请输入客户简称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="组织机构代码:" prop="agencyCode">
                <el-input v-model="form.agencyCode" placeholder="请输入组织机构代码" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="法人:" prop="legalPerson">
                <el-input v-model="form.legalPerson" placeholder="请输入法人" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="联系人:" prop="contact" class="icon-star">
                <el-input v-model="form.contact" placeholder="请输入联系人" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联系电话:" prop="contactNumber">
                <el-input v-model="form.contactNumber" placeholder="请输入联系电话" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="电子邮箱:" prop="mail">
                <el-input v-model="form.mail" placeholder="请输入电子邮箱" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="销售区域:" prop="salesArea">
                <treeselect v-model="form.salesArea" :options="areaListOptions" :normalizer="areaNormal" placeholder="选择销售区域" noOptionsText="暂无数据" @select="changeSelectSalesArea" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="客户分类:" prop="customerSortId">
                <treeselect v-model="form.customerSortId" :options="userListOptions" :normalizer="userListNormal" placeholder="选择客户分类" noOptionsText="暂无数据" @select="changeSelectUserlist" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="行业类型:" prop="industryType">
                <el-select v-model="form.industryType" style="width:100%;" placeholder="请选择">
                  <el-option
                    v-for="item in industryTypeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="币种:" prop="currency" class="icon-star">
                <el-select v-model="form.currency" style="width:100%;">
                  <el-option
                    v-for="item in currencyList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="客户来源:" prop="customerSource">
                <el-input v-model="form.customerSource" placeholder="请输入客户来源" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="销售员:" prop="seller">
                <el-input v-model="form.seller" placeholder="请输入销售员" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="价格清单:" prop="priceList">
                <el-input v-model="form.priceList" placeholder="请输入价格清单" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="运输方式:" prop="transport">
                <el-select v-model="form.transport" style="width:100%;">
                  <el-option
                    v-for="item in transportList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="付款条件:" prop="paymentTerms">
                <el-input v-model="form.paymentTerms" placeholder="请输入付款条件" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="收货人:" prop="consignee">
                <el-input v-model="form.consignee" placeholder="请输入收货人" />
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <el-form-item label="收货地址:" class="icon-star">
                <el-select v-model="form.province" placeholder="请选择" @change="val => selectProvince(val, 'address')" class="mr10 width160 mb10">
                  <el-option v-for="(item,index) of provinceArr" :key="index" :label="item.name" :value="item.name"></el-option>
                </el-select>
                <el-select v-model="form.city" placeholder="请选择" @change="val => selectCity(val, 'address')" class="mr10 width180 mb10">
                  <el-option v-for="(item,index) of cityArr" :key="index" :label="item.name" :value="item.name"></el-option>
                </el-select>
                <el-select placeholder="请选择" v-model="form.region" class="mr10 width160 mb10">
                  <el-option v-for="(item,index) of regionArr" :key="index" :label="item.name" :value="item.name"></el-option>
                </el-select>
                <el-input v-model="form.shippingAddress" placeholder="详情地址" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
           <el-col :span="8">
            <el-form-item label="状态:" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio :label="1">正常</el-radio>
                <el-radio :label="0">禁用</el-radio>
              </el-radio-group>
             </el-form-item>
           </el-col>
        </el-row>
        </div>
        <div v-show="current === 1">
          <!-- 营业执照 -->
          <el-row class="display">
            <el-col :span="8" class="display">
              <div class="upload-title">营业执照</div>
              <el-upload
                class="avatar-uploader"
                action="#"
                :auto-upload="false"
                :on-change="(file) => {onUploadType(file, 1)}"
                :show-file-list="false"
              >
                <div v-if="JSON.stringify(typeList1) !== '{}'">
                  <img v-if="typeList1.fileType == '.jpg' || typeList1.fileType == '.png' || typeList1.fileType == '.gif' || typeList1.fileType == '.bmp' || typeList1.fileType == 'jpeg'" :src="typeList1.fileUrl" class="avatar">
                  <span v-else>{{ typeList1.fileName }}</span>
                </div>
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-col>
            <el-col :span="8">
              <el-form-item label="开始日期:">
                <el-date-picker v-model="typeList1.startTime" suffix-icon="el-icon-date" type="date" value-format="yyyy-MM-dd" placeholder="请选择开始日期" @change="(val) => {onStartTime(val, 1)}">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="结束日期:">
                <el-date-picker v-model="typeList1.endTime" suffix-icon="el-icon-date" type="date" value-format="yyyy-MM-dd" placeholder="请选择完成日期" @change="(val) => {onEndTime(val, 1)}">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 年度报告 -->
          <el-row class="display">
            <el-col :span="8" class="display">
              <div class="upload-title">年度报告</div>
              <el-upload
                class="avatar-uploader"
                action="#"
                :auto-upload="false"
                :on-change="(file) => {onUploadType(file, 2)}"
                :show-file-list="false"
              >
                <div v-if="JSON.stringify(typeList2) !== '{}'">
                  <img v-if="typeList2.fileType == '.jpg' || typeList2.fileType == '.png' || typeList2.fileType == '.gif' || typeList2.fileType == '.bmp' || typeList2.fileType == 'jpeg'" :src="typeList2.fileUrl" class="avatar">
                  <span v-else>{{ typeList2.fileName }}</span>
                </div>
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-col>
            <el-col :span="8">
              <el-form-item label="开始日期:">
                <el-date-picker v-model="typeList2.startTime" suffix-icon="el-icon-date" type="date" value-format="yyyy-MM-dd" placeholder="请选择开始日期" @change="(val) => {onStartTime(val, 2)}">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="结束日期:">
                <el-date-picker v-model="typeList2.endTime" suffix-icon="el-icon-date" type="date" value-format="yyyy-MM-dd" placeholder="请选择完成日期" @change="(val) => {onEndTime(val, 2)}">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 医疗器械经营许可证 -->
          <el-row class="display">
            <el-col :span="8" class="display">
              <div class="upload-title">医疗器械经营许可证</div>
              <el-upload
                class="avatar-uploader"
                action="#"
                :auto-upload="false"
                :on-change="(file) => {onUploadType(file, 3)}"
                :show-file-list="false"
              >
                <div v-if="JSON.stringify(typeList3) !== '{}'">
                  <img v-if="typeList3.fileType == '.jpg' || typeList3.fileType == '.png' || typeList3.fileType == '.gif' || typeList3.fileType == '.bmp' || typeList3.fileType == 'jpeg'" :src="typeList3.fileUrl" class="avatar">
                  <span v-else>{{ typeList3.fileName }}</span>
                </div>
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-col>
            <el-col :span="8">
              <el-form-item label="开始日期:">
                <el-date-picker v-model="typeList3.startTime" suffix-icon="el-icon-date" type="date" value-format="yyyy-MM-dd" placeholder="请选择开始日期" @change="(val) => {onStartTime(val, 3)}">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="结束日期:">
                <el-date-picker v-model="typeList3.endTime" suffix-icon="el-icon-date" type="date" value-format="yyyy-MM-dd" placeholder="请选择完成日期" @change="(val) => {onEndTime(val, 3)}">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 质量保证协议 -->
          <el-row class="display">
            <el-col :span="8" class="display">
              <div class="upload-title">质量保证协议</div>
              <el-upload
                class="avatar-uploader"
                action="#"
                :auto-upload="false"
                :on-change="(file) => {onUploadType(file, 4)}"
                :show-file-list="false"
              >
                <div v-if="JSON.stringify(typeList4) !== '{}'">
                  <img v-if="typeList4.fileType == '.jpg' || typeList4.fileType == '.png' || typeList4.fileType == '.gif' || typeList4.fileType == '.bmp' || typeList4.fileType == 'jpeg'" :src="typeList4.fileUrl" class="avatar">
                  <span v-else>{{ typeList4.fileName }}</span>
                </div>
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-col>
            <el-col :span="8">
              <el-form-item label="开始日期:">
                <el-date-picker v-model="typeList4.startTime" suffix-icon="el-icon-date" type="date" value-format="yyyy-MM-dd" placeholder="请选择开始日期" @change="(val) => {onStartTime(val, 4)}">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="结束日期:">
                <el-date-picker v-model="typeList4.endTime" suffix-icon="el-icon-date" type="date" value-format="yyyy-MM-dd" placeholder="请选择完成日期" @change="(val) => {onEndTime(val, 4)}">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div v-show="current === 2">
          <el-row>
            <el-col :span="8">
              <el-form-item label="公司名称（中文）:" prop="customerInformationInvoice.name">
                <el-input v-model="form.customerInformationInvoice.name" placeholder="请输入公司名称（中文）" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="公司名称（英文）:" prop="customerInformationInvoice.enName">
                <el-input v-model="form.customerInformationInvoice.enName" placeholder="请输入公司名称（英文）" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="公司注册地址:">
                <el-select v-model="form.customerInformationInvoice.registeredAddressCountry" placeholder="请选择" class="mr10 width100">
                  <el-option label="中国" value="中国" ></el-option>
                </el-select>
                <el-select v-model="form.customerInformationInvoice.registeredAddressProvince" placeholder="请选择" @change="selectProvince" class="mr10 width180">
                  <el-option v-for="(item,index) of provinceArr" :key="index" :label="item.name" :value="item.name"></el-option>
                </el-select>
                <el-select v-model="form.customerInformationInvoice.registeredAddressCity" placeholder="请选择" @change="selectCity" class="mr10 width180">
                  <el-option v-for="(item,index) of cityArr" :key="index" :label="item.name" :value="item.name"></el-option>
                </el-select>
                <el-select placeholder="请选择" v-model="form.customerInformationInvoice.registeredAddressRegion" class="mr10 width180">
                  <el-option v-for="(item,index) of regionArr" :key="index" :label="item.name" :value="item.name"></el-option>
                </el-select>
                <el-input v-model="form.customerInformationInvoice.registeredAddressDetailed" placeholder="" style="width:30%;" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="纳税人类型:" prop="customerInformationInvoice.taxpayerType">
                <el-radio-group v-model="form.customerInformationInvoice.taxpayerType">
                  <el-radio :label="0">增值税一般纳税人</el-radio>
                  <el-radio :label="1">增值税小规模纳税人</el-radio>
                  <el-radio :label="2">营业纳税人</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="纳税类型比例:" prop="customerInformationInvoice.taxpayerScale">
                <el-radio-group v-model="form.customerInformationInvoice.taxpayerScale">
                  <el-radio :label="0">13%</el-radio>
                  <el-radio :label="1">9%</el-radio>
                  <el-radio :label="2">6%</el-radio>
                  <el-radio :label="3">3%</el-radio>
                  <el-radio :label="4">1%</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="电话:" prop="customerInformationInvoice.phone">
                <el-input v-model="form.customerInformationInvoice.phone" placeholder="请输入电话" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="传真:" prop="customerInformationInvoice.fax">
                <el-input v-model="form.customerInformationInvoice.fax" placeholder="请输入传真" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="美元开户银行名称:" prop="customerInformationInvoice.usBankAccountName">
                <el-input v-model="form.customerInformationInvoice.usBankAccountName" placeholder="请输入美元开户银行名称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="美元开户银行账号:" prop="customerInformationInvoice.usBankAccount">
                <el-input v-model="form.customerInformationInvoice.usBankAccount" placeholder="请输入美元开户银行名称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="开户银行名称:" prop="customerInformationInvoice.cnBankAccountName">
                <el-input v-model="form.customerInformationInvoice.cnBankAccountName" placeholder="请输入开户银行名称" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="开户银行账号:" prop="customerInformationInvoice.cnBankAccount">
                <el-input v-model="form.customerInformationInvoice.cnBankAccount" placeholder="请输入开户银行账号" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import { addUser, editUser } from "@/api/system/basedata/user/user";
import { uploadImg } from "@/api/system/upload/upload";
import { listSalesArea, checkSalesArea } from "@/api/system/basedata/salesarea/salesarea";
import { listToAddUserList, checkUserList } from "@/api/system/basedata/userlist/userlist";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { province } from '@/commonJs/linkage.js';
export default {
  name: "userAdd",
  components: { Treeselect },
  data(){
    return {
      current: 0,
      form: {
        code: '',
        name: '',
        englishName: '',
        abbreviation: '',
        agencyCode: '',
        legalPerson: '',
        contact: '',
        contactNumber: '',
        mail: '',
        salesArea: undefined,
        customerSortId: undefined,
        industryType: '',
        currency: '',
        customerSource: '',
        seller: '',
        priceList: '',
        transport: '',
        paymentTerms: '',
        consignee: '',
        province: '',
        city: '',
        region: '',
        shippingAddress: '',
        status: 1,
        customerInformationFileList: [],
        customerInformationInvoice: {
          name: '',
          enName: '',
          registeredAddressCountry: '',
          registeredAddressProvince: '',
          registeredAddressCity: '',
          registeredAddressRegion: '',
          registeredAddressDetailed: '',
          taxpayerType: '',
          taxpayerScale: '',
          phone: '',
          fax: '',
          usBankAccountName: '',
          usBankAccount: '',
          cnBankAccountName: '',
          cnBankAccount: ''
        }
      },
      areaListOptions: [],
      userListOptions: [],
      industryTypeList: [
        {
          value: '默认'
        },
        {
          value: '金融业'
        },
        {
          value: '证劵业'
        },
        {
          value: '软件业'
        },
        {
          value: '医药行业'
        },
        {
          value: '其他'
        }
      ],
      currencyList: [
        {
          value: '人民币'
        },
        {
          value: 'USD'
        }
      ],
      transportList: [
        {
          value: '汽车运输'
        },
        {
          value: '航空运输'
        },
        {
          value: '需方自提'
        }
      ],
      typeList1: {},
      typeList2: {},
      typeList3: {},
      typeList4: {},
      provinceArr: [],
      cityArr: [],
      regionArr: [],
      id: ''
    }
  },
  created() {
    this.getSalesArea()
    this.getUserList()
    this.provinceArr = province
  },
  methods: {
    // 获取销售区域
    getSalesArea(){
      listSalesArea().then(res => {
        this.areaListOptions = this.handleTree(res.rows, "areaId")
      })
    },
    // 检测销售区域是否含有子集
    changeSelectSalesArea(e){
      // console.log(e)
      checkSalesArea(e.areaId).then(res => {
        // console.log(res)
        if(res.code == 103){
          this.form.salesArea = undefined
          this.$modal.msgError(res.msg)
        }
      })
    },
    // 转换销售区域数据结构 
    areaNormal(e) {
      if (e.children && !e.children.length) {
        delete e.children
      }
      return {
        id: e.areaId,
        label: e.areaName,
        children: e.children
      }
    },
    // 获取客户分类
    getUserList() {
      listToAddUserList().then(res => {
        this.userListOptions = this.handleTree(res.data, "sortId")
      })
    },
    // 检测客户分类是否含有子集
    changeSelectUserlist(e){
      checkUserList(e.sortId).then(res => {
        // console.log(res)
        if(res.code == 103){
          this.form.customerSortId = undefined
          this.$modal.msgError(res.msg)
        }
      })
    },
    // 转换客户分类数据结构
    userListNormal(e){
      if (e.children && !e.children.length) {
        delete e.children
      }
      return {
        id: e.sortId,
        label: e.sortName,
        children: e.children
      }
    },
    // 上传文件
    onUploadType(e, item){
      this.$modal.loading("正在上传")
      let formData = new FormData()
      let file = e.raw
      formData.append('file', file)
      uploadImg(formData).then(res => {
        this.$modal.closeLoading()
        this.$modal.msgSuccess("上传成功")
        let obj = res.data
        if(item == 1){
          this.typeList1 = res.data
          obj.type = 1 // 营业执照
        }else if(item == 2){
          this.typeList2 = res.data
          obj.type = 2 // 年度报告
        }else if(item == 3){
          this.typeList3 = res.data
          obj.type = 3 // 医疗器械经营许可证
        }else{
          this.typeList4 = res.data
          obj.type = 4 // 质量保证协议
        }
        if(this.form.customerInformationFileList.length > 0){
          const idx = this.form.customerInformationFileList.findIndex(i => i.type == obj.type)
          idx < 0 ? this.form.customerInformationFileList.push(obj) : this.form.customerInformationFileList.splice(idx, 1, obj)
        }else{
          this.form.customerInformationFileList.push(obj)
        }
        // console.log(this.form.customerInformationFileList)
      })
    },
    // 开始时间
    onStartTime(e, item){
      if(item == 1){
        if(this.form.customerInformationFileList.length > 0){
          this.form.customerInformationFileList.forEach(i => {
            if(i.type == 1){
              i.startTime = e
            }
          })
        }else{
          this.$modal.msgError('请上传营业执照！')
          this.typeList1 = {}
        }
      }else if(item == 2){
        if(this.form.customerInformationFileList.length > 0){
          this.form.customerInformationFileList.forEach(i => {
            if(i.type == 2){
              i.startTime = e
            }
          })
        }else{
          this.$modal.msgError('请上传年度报告！')
          this.typeList2 = {}
        }
      }else if(item == 3){
        if(this.form.customerInformationFileList.length > 0){
          this.form.customerInformationFileList.forEach(i => {
            if(i.type == 3){
              i.startTime = e
            }
          })
        }else{
          this.$modal.msgError('请上传医疗器械经营许可证！')
          this.typeList3 = {}
        }
      }else{
        if(this.form.customerInformationFileList.length > 0){
          this.form.customerInformationFileList.forEach(i => {
            if(i.type == 4){
              i.startTime = e
            }
          })
        }else{
          this.$modal.msgError('请上传质量保证协议！')
          this.typeList4 = {}
        }
      }
    },
    // 结束时间
    onEndTime(e, item){
      if(item == 1){
        if(this.form.customerInformationFileList.length > 0){
          this.form.customerInformationFileList.forEach(i => {
            if(i.type == 1){
              i.endTime = e
            }
          })
        }else{
          this.$modal.msgError('请上传营业执照！')
          this.typeList1 = {}
        }
      }else if(item == 2){
        if(this.form.customerInformationFileList.length > 0){
          this.form.customerInformationFileList.forEach(i => {
            if(i.type == 2){
              i.endTime = e
            }
          })
        }else{
          this.$modal.msgError('请上传年度报告！')
          this.typeList2 = {}
        }
      }else if(item == 3){
        if(this.form.customerInformationFileList.length > 0){
          this.form.customerInformationFileList.forEach(i => {
            if(i.type == 3){
              i.endTime = e
            }
          })
        }else{
          this.$modal.msgError('请上传医疗器械经营许可证！')
          this.typeList3 = {}
        }
      }else{
        if(this.form.customerInformationFileList.length > 0){
          this.form.customerInformationFileList.forEach(i => {
            if(i.type == 4){
              i.endTime = e
            }
          })
        }else{
          this.$modal.msgError('请上传质量保证协议！')
          this.typeList4 = {}
        }
      }
    },
    // 省份
    selectProvince(name, type){
      if(type == 'address'){
        // console.log(type)
        this.cityArr = []
        this.regionArr = []
        this.form.city = ''
        this.form.region = ''
        for (let item of this.provinceArr) {
          if (name == item.name) {
            this.cityArr = item.children
          }
        }
      }else{
        this.cityArr = []
        this.regionArr = []
        this.form.customerInformationInvoice.registeredAddressCity = ''
        this.form.customerInformationInvoice.registeredAddressRegion = ''
        for (let item of this.provinceArr) {
          if (name == item.name) {
            this.cityArr = item.children
          }
        }
      }
    },
    // 城市
    selectCity (name, type) {
      if(type == 'address'){
        this.regionArr = []
        this.form.region = ''
        for (let item of this.cityArr) {
          if (name == item.name) {
            this.regionArr = item.children
          }
        }
      }else{
        this.regionArr = []
        this.form.customerInformationInvoice.registeredAddressRegion = ''
        for (let item of this.cityArr) {
          if (name == item.name) {
            this.regionArr = item.children
          }
        }
      }
    },
    // 提交数据
    submitForm(e) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // console.log(this.form)
          if(e == 1){
            if(this.id){
              let arr = this.form
              arr.id = this.id
              arr.approvalStatus = 0
              this.$modal.loading("正在保存")
              editUser(arr).then(res => {
                if(res.code == 200){
                  this.$modal.msgSuccess("保存成功!")
                  this.$modal.closeLoading()
                }
              })
            }else{
              let arr = this.form
              arr.approvalStatus = 0
              this.$modal.loading("正在保存")
              addUser(this.form).then(res=> {
                // console.log(res)
                if(res.code == 200){
                  this.id = res.data.id
                  this.form.customerInformationInvoice = res.data.customerInformationInvoice
                  this.$modal.msgSuccess("保存成功")
                  this.$modal.closeLoading()
                }
              })
            }
          }else{
            if(this.id){
              if(this.form.name == undefined || this.form.name == ''){
                this.$modal.msgError('客户全称不能为空！')
              }
              // else if(this.form.agencyCode == undefined || this.form.agencyCode == ''){
              //   this.$modal.msgError('组织机构代码不能为空！')
              // }
              else if(this.form.contact == undefined || this.form.contact == ''){
                this.$modal.msgError('联系人不能为空！')
              }else if(this.form.currency == undefined || this.form.currency == ''){
                this.$modal.msgError('币种不能为空！')
              }
              // else if(this.form.priceList == undefined || this.form.priceList == ''){
              //   this.$modal.msgError('价格清单不能为空！')
              // }
              else{
                let arr = this.form
                arr.id = this.id
                arr.approvalStatus = 1
                this.$modal.loading("正在提交")
                editUser(arr).then(res => {
                  if(res.code == 200){
                    this.$refs.form.resetFields()
                    this.$tab.closeOpenPage({ path: "/customer/user/user" })
                    this.$modal.msgSuccess("新建成功!")
                    this.$modal.closeLoading()
                  }
                })
              }
            }else{
              if(this.form.name == undefined || this.form.name == ''){
                this.$modal.msgError('客户全称不能为空！')
              }
              // else if(this.form.agencyCode == undefined || this.form.agencyCode == ''){
              //   this.$modal.msgError('组织机构代码不能为空！')
              // }
              else if(this.form.contact == undefined || this.form.contact == ''){
                this.$modal.msgError('联系人不能为空！')
              }else if(this.form.currency == undefined || this.form.currency == ''){
                this.$modal.msgError('币种不能为空！')
              }
              // else if(this.form.priceList == undefined || this.form.priceList == ''){
              //   this.$modal.msgError('价格清单不能为空！')
              // }
              else{
                let arr = this.form
                arr.approvalStatus = 1
                this.$modal.loading("正在提交")
                addUser(arr).then(res=> {
                  // console.log(res)
                  if(res.code == 200){
                    this.$refs.form.resetFields()
                    this.$tab.closeOpenPage({ path: "/customer/user/user" })
                    this.$modal.msgSuccess("新建成功!")
                    this.$modal.closeLoading()
                  }
                })
              }
            }
          }
        }
      })
    }
  }
}
</script>

<style scoped>
.upload-title{
  width: 140px;
  padding-right: 10px;
  color: #606266;
  font-size: 14px;
  font-weight: bold;
  text-align: right;
}
.avatar-uploader{
  display: flex;
  align-items: center;
  justify-content: center;
  color:#606266;
  width: 178px;
  height: 178px;
  margin-bottom: 22px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader:hover {
  border-color: #5ED4D4;
}
.avatar-uploader:hover .avatar-uploader-icon{
  color: #5ED4D4;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  display: block;
}
</style>